{include file="public/header"}
  
  <body>
    <div class="x-body">
        <form class="layui-form">
           <div class="layui-form-item">
              <label for="L_email" class="layui-form-label">
                  <span class="x-red">*</span>分类名称
              </label>
              <div class="layui-input-inline">
              	<input type="hidden" name="id" id="id" value="{$data.id}" />
                  <input type="text" id="name" name="name"
                  autocomplete="off" class="layui-input" value="{$data.name}">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="L_email" class="layui-form-label">
                  <span class="x-red">*</span>排序
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="sort" name="sort"
                  autocomplete="off" class="layui-input" value="{$data.sort}">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
              </label>
              <button  class="layui-btn" lay-filter="add" id="submit">
                  确定
              </button>
          </div>
      </form>
    </div>
    {include file="public/base_js"}
    <script>
      layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form
        ,layer = layui.layer;
      	var defaultData = {
      		 name : "{$data.name}",
      		 sort: "{$data.sort}"
      	};

        $('#submit').on('click',function () {
	        	if ((defaultData.name == $('#name').val()) && (defaultData.sort == $('#sort').val())) {
	        		layer.msg('无任何修改!', {
								icon: 2,
								time: 1000
							});
							return false;
	        	}
        		var reg = /^\d+$/;
        		var sortVal = Number($('#sort').val());
        		console.log(typeof sortVal);
        		if (!reg.test(sortVal)) {
        			layer.msg('排序必须为数字');
        			return false;
        		}
            $.ajax({
                type:'post',
                url: "{:url('admin/CaseClass/update_class')}",
                data: $('.layui-form').serialize(),
                dataType:'json',
                success:function (data) {
                    if (data.success) {
                        layer.msg(data.msg, { 'icon': 1,'time': 500} ,function(){
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                            window.localStorage.setItem('update_case_class',new Date().getTime()); 
                        });
                    } else {
                        layer.msg(JSON.stringify(data.msg), { 'icon': 2,'time': 500} );
                    }
                }
            });
            return false;
        });
      });
  </script>
  </body>

</html>